package com.xbongbong.pro.dataset.node;

import com.google.common.collect.Maps;
import com.xbongbong.paas.enums.bi.DataSetNodeTypeEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;

/**
 * @author gzt
 * @version 1.0
 * @Description -
 * @datetime - 2022/5/23-10:40
 * @since v1.0
 */
@Component
public class NodeStrategyFactory {
    @Resource
    InputNodeStrategy inputNodeStrategy;
    @Resource
    UnionNodeStrategy unionNodeStrategy;
    @Resource
    JoinNodeStrategy joinNodeStrategy;
    @Resource
    GroupNodeStrategy groupNodeStrategy;
    @Resource
    OutputNodeStrategy outputNodeStrategy;

    private static final Map<String,NodeStrategy> NODE_STRATEGIES_MAP = Maps.newHashMap();

    @PostConstruct
    public void init() {
        NODE_STRATEGIES_MAP.putIfAbsent(DataSetNodeTypeEnum.INPUT.getAlias(),inputNodeStrategy);
        NODE_STRATEGIES_MAP.putIfAbsent(DataSetNodeTypeEnum.UNION.getAlias(),unionNodeStrategy);
        NODE_STRATEGIES_MAP.putIfAbsent(DataSetNodeTypeEnum.JOIN.getAlias(),joinNodeStrategy);
        NODE_STRATEGIES_MAP.putIfAbsent(DataSetNodeTypeEnum.GROUP.getAlias(),groupNodeStrategy);
        NODE_STRATEGIES_MAP.putIfAbsent(DataSetNodeTypeEnum.OUTPUT.getAlias(),outputNodeStrategy);
    }



        public static NodeStrategy getStrategy(String type) {
            if (StringUtils.isEmpty(type)){return null;}
            return NODE_STRATEGIES_MAP.get(type);
        }

}
